package com.cxy.controller.admin;

import com.cxy.dto.InformationDTO;
import com.cxy.dto.InformationImportDTO;
import com.cxy.dto.InformationScoreDTO;
import com.cxy.result.PageResult;
import com.cxy.result.Result;
import com.cxy.service.InformationService;
import com.cxy.vo.InformationUpdateVO;
import com.cxy.vo.InformationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 评议信息管理
 */
@Api(tags = "评议信息管理")
@RestController
@RequestMapping("/information")
@Slf4j
public class InformationController {
    @Autowired
    private InformationService informationService;
    /**
     * 评议信息管理分页查询
     */
    @ApiOperation("评议信息管理分页查询")
    @GetMapping("/page")
    public Result<PageResult> page( InformationDTO informationDTO){
        PageResult pageResult = informationService.page(informationDTO);
        return Result.success(pageResult);
    }
    /**
     * 修改评分
     */
    @ApiOperation("修改评分")
    @PutMapping("/update")
    public Result updateScore(@RequestBody InformationScoreDTO informationScoreDTO){
        informationService.update(informationScoreDTO);
        return Result.success();
    }
    /**
     * 根据id查询详细评议信息
     */
    @ApiOperation("根据id查询详细评议信息")
    @GetMapping("/select/{id}")
    public Result<InformationUpdateVO> getById(@PathVariable Long id){
        InformationUpdateVO informationUpdateVO = informationService.getById(id);
       return Result.success(informationUpdateVO);
    }
    /**
     * 导出模板
     */
    @ApiOperation("导出评议信息模板")
    @GetMapping("/export")
    public void export(HttpServletResponse response, HttpServletRequest request){
        informationService.export(response,request);
    }
    /**
     * 导入评议信息数据文件
     */
    @ApiOperation("导入评议信息数据文件")
    @GetMapping("/import")
    public Result dataImport(MultipartFile file) throws IOException {
        System.out.println("文件大小:"+file.getSize());
        System.out.println("资源名称:"+file.getResource());
        informationService.dataImport(file);
        return Result.success();
    }
    /**
     * 导入数据成绩修改
     */
    @PutMapping("ImportUpdate")
    @ApiOperation("导入数据成绩修改")
    public Result ImportUpdate(@RequestBody InformationImportDTO informationImportDTO){
        informationService.ImportUpdate(informationImportDTO);
        return Result.success();
    }
}
